package org.jwt.oauth.user;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.jwt.oauth.tools.ThreadLocalTool;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;

public class FusionUserDetails implements UserDetails {
	
	private static final long serialVersionUID = 1L;
	
	private String username;
	private String password;
	private boolean enabled=true;
	private boolean accountNonExpired=true;
	private boolean accountNonLocked=true;
	private boolean credentialsNonExpired=true;
	private Collection<? extends GrantedAuthority> authorities=AuthorityUtils.commaSeparatedStringToAuthorityList("");
	//需要返回的值
	private Map<String,Object> responseMap=new HashMap<String,Object>();
	//不需要返回的值
	private Map<String,Object> dataMap=new HashMap<String,Object>();
	
	public FusionUserDetails(String username,String password) {
		this.username=username;
		this.password=password;
		ThreadLocalTool.set(true);
	}
	
	public FusionUserDetails(String username,String password,boolean checkPassword) {
		this.username=username;
		this.password=password;
		ThreadLocalTool.set(checkPassword);
	}

	public Map<String, Object> getDataMap() {
		dataMap.putAll(this.getResponseMap());
		return dataMap;
	}
	
	public Map<String, Object> getResponseMap() {
		return responseMap;
	}
	
	public void putResponse(String key,Object value) {
		this.responseMap.put(key, value);
	}
	
	public void putData(String key,Object value) {
		this.dataMap.put(key, value);
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public boolean isAccountNonExpired() {
		return accountNonExpired;
	}

	public void setAccountNonExpired(boolean accountNonExpired) {
		this.accountNonExpired = accountNonExpired;
	}

	public boolean isAccountNonLocked() {
		return accountNonLocked;
	}

	public void setAccountNonLocked(boolean accountNonLocked) {
		this.accountNonLocked = accountNonLocked;
	}

	public boolean isCredentialsNonExpired() {
		return credentialsNonExpired;
	}

	public void setCredentialsNonExpired(boolean credentialsNonExpired) {
		this.credentialsNonExpired = credentialsNonExpired;
	}

	public Collection<? extends GrantedAuthority> getAuthorities() {
		return authorities;
	}

	public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
		this.authorities = authorities;
	}
}
